package com.ck.ips.controller;

import com.ck.common.model.OperationResult;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.util.HttpUtils;
import com.ck.ips.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
* @Description: 登录controller
* @Author: hf
* @Date:    2019/4/29 9:43
* @Version: 1.0
*/
@RestController
public class LoginController extends BaseController{
    private static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public OperationResult login(String userName, String password,String imageCode, HttpServletRequest request) {
        OperationResult loginResult = loginService.doLogin(userName, password, imageCode,HttpUtils.getRemortIP(request));
       return loginResult;
    }

    /**
     * 登录
     */
    @PostMapping("/h5login")
    public OperationResult h5Login(String userName, String password, HttpServletRequest request) {
        OperationResult loginResult = loginService.doH5Login(userName, password, null,HttpUtils.getRemortIP(request));
        return loginResult;
    }


    /**
     * 注销登录
     */
    @LoginRequired
    @PostMapping(value = "/logout")
    public OperationResult doLogOut() {
        super.logOut();
        return  OperationResult.newSuccessOperationResult();
    }

}
